import java.util.ArrayList;
import java.util.Map;
import java.util.stream.Collectors;

class Student{
    String name;
    String age;

    public Student(String name,String age){
        this.name=name;
        this.age=age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
}


/**
 * @author admin
 * jdk1.8 lambda表达式一行便可以将list转成map
 */
public class Test {

    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student("will","12"));
        list.add(new Student("okada","34"));
        Map<String, String> map1 = list.stream().collect(Collectors.toMap(Student::getName, Student::getAge));
        System.out.println("====values值为年龄====");
        map1.forEach((key,value)->{
            System.out.println(key);
            System.out.println(value);
        });

        Map<String, Student> map2 = list.stream().collect(Collectors.toMap(Student::getName, Student -> Student));
        System.out.println("====values为对象====");
        map2.forEach((key,value)->{
            System.out.println(key);
            System.out.println(value);
        });

    }

}
